package com.server.modules.sys.scheduled;

import com.server.modules.api.service.IMService;
import com.server.modules.sys.entity.member.Member;

import com.server.modules.sys.service.member.MemberService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 金贤哲 on 2017/3/10 0010.
 */
@Component
public class ScheduleNewMemberTask {

    @Resource
    private MemberService memberService;
    @Resource
    private IMService imService;

    /**
     * 每天10:00给客服发消息
     */
    @Scheduled(cron = "0 0 10 * * * ")
    public void tasknewmember() {
        List<Member> tasknewmember = memberService.newmember();
        Map<String, String> msg = new HashedMap();
        msg.put("type", "text");
        msg.put("msg", "有新客户在移动端选了你负责的产品，请尽快在后台查看");
        List<String> userList = new ArrayList<String>(1);
        for (Member member : tasknewmember) {
            userList.add(member.getHxUsername());
        }
        //3.调接口，发送消息
        imService.sendSysMessages(userList, msg, null);

    }
}
